<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-row>
        <el-col :span="8">
          <el-input placeholder="请输入内容"  clearable v-model='dataForm.query' @clear='getData'>
            <el-button slot="append" icon="el-icon-search" @click='getData'></el-button>
          </el-input>
        </el-col>
      </el-row>
      <el-table border stripe style="width: 100%" :data='dataList'>
        <el-table-column type='index' ></el-table-column>
        <el-table-column label='订单编号' prop='order_number'></el-table-column>
        <el-table-column label='订单价格' prop='order_price' width='90px'></el-table-column>
        <el-table-column label='是否付款' width='90px'>
          <template slot-scope='scope'>
            <el-tag type="success" v-if='scope.row.pay_status == 1'>已付款</el-tag>
            <el-tag type="warning" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label='是否发货' prop='is_send' width='90px'></el-table-column>
        <el-table-column label='下单时间' width='110px'>
          <template slot-scope='scope'>
            {{ scope.row.create_time | timeInfo }}
          </template>
        </el-table-column>
        <el-table-column label='操作' width='130px'>
          <template>
            <el-button size='mini' type="primary" icon="el-icon-edit" @click='showBox'></el-button>
            <el-button size='mini' type="success" icon="el-icon-location" @click='press'></el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="dataForm.pagenum"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="dataForm.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
      <el-dialog
        title="修改地址"
        :visible.sync="dialogVisible"
        width="50%">
        <el-form :model="address" :rules="addressrules" ref="ref_address" label-width="100px">
          <el-form-item label="省市区/县" prop="address1">
            <el-input v-model="address.address1"></el-input>
          </el-form-item>
          <el-form-item label="详细地址" prop="address2">
            <el-input v-model="address.address2"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
        </span>
      </el-dialog>
      <el-dialog
        title="物流进度"
        :visible.sync="preVisible"
        width="50%">
        <el-timeline>
          <el-timeline-item
            v-for="(activity, index) in preData"
            :key="index"
            :timestamp="activity.time">
            {{activity.context}}
          </el-timeline-item>
        </el-timeline>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
export default {
  data(){
    return {
      address:{
        address1:[],
        address2:'',
      },
      addressrules:{
        address1:[
           { required: true, message: '请选择省市区/县', trigger: 'blur' },
        ],
        address2:[
           { required: true, message: '请填写详细地址', trigger: 'blur' },
        ]
      },
      preVisible:false,
      dialogVisible:false,
      total:0,
      preData:[],
      dataForm:{
        query:'',
        pagenum:1,
        pagesize:10,
      },
      dataList:[],
    }
  },
  filters:{
    timeInfo(data){
      let time = new Date(data)
      return time.getFullYear() + '-' + time.getMonth() + 1 + '-' + time.getDate()
    }
  },
  methods:{
    handleSizeChange(size) {
      this.dataForm.pagesize = size
      this.getData()
    },
    handleCurrentChange(num) {
      this.dataForm.pagenum = num
      this.getData()
    },
    async getData() {
      let res = await this.axios.get('/orders', {
        params: this.dataForm
      })
      if( res.data.meta.status == 200 ){
        this.total = res.data.data.total
        this.dataList = res.data.data.goods
      } else {
        this.pop.error(res.data.meta.msg)
      }
    },
    showBox(){
      this.dialogVisible = true
    },
    async press(){
      let res = await this.axios.get(`/kuaidi/1106975712662`)
      if( res.data.meta.status == 200 ) {
        this.preData = res.data.data
      } else {
        this.pop.error(res.data.meta.msg)
      }
      this.preVisible = true
    }
  },
  created(){
    this.getData()
  } 
}
</script>

<style lang='scss' scoped>
.el-breadcrumb {
  padding:15px 0;
}
</style>